using GameFramework;
using Unity.VisualScripting;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace LS.UGFUnits
{
    [UnitShortTitle("Config")]
    [UnitSurtitle("Add")]
    public sealed class RemoveConfig : ConfigUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput Key { get; private set; }
        
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput Result { get; private set; }
        
        protected override void Definition()
        {
            base.Definition();
            Key = ValueInput<string>(nameof(Key), string.Empty);
            Result =  ValueOutput<bool>(nameof(Result));
            
            Requirement(Key, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            if (Target == null)
            {
                Debug.LogError("GameFramework is not initialized.");
                return Output;
            }

            string key = flow.GetValue<string>(Key);
            bool result = Target?.RemoveConfig(key) ?? false;
            flow.SetValue(Result, result);
            return base.In(flow);
        }
        
    }
}